package com.github.winyiwin.queue;


import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.SynchronousQueue;

public enum QueueEnum {

    ArrayBlockingQueue {
        @Override
        public ArrayBlockingQueue createQueue(int capacity, boolean fair) {
            return new ArrayBlockingQueue(capacity, fair);
        }
    },
    LinkedBlockingQueue {
        @Override
        public LinkedBlockingQueue createQueue(int capacity, boolean fair) {
            return new LinkedBlockingQueue(capacity);
        }
    },
    SynchronousQueue {
        @Override
        public SynchronousQueue createQueue(int capacity, boolean fair) {
            return new SynchronousQueue(fair);
        }
    },
    ResizableBlockingQueue {
        @Override
        public BlockingQueue createQueue(int capacity, boolean fair) {
            return new ResizableBlockingQueue();
        }
    };

    public abstract BlockingQueue createQueue(int capacity, boolean fair);

    public static QueueEnum getInstance(QueueEnum queueEnum) {
        for (QueueEnum value : QueueEnum.values()) {
            if (value == queueEnum) {
                return value;
            }
        }
        return null;
    }
}
